<%-- 
    Document   : empleado
    Created on : Oct 12, 2012, 2:06:33 PM
    Author     : Jah
--%>

<%@page import="tickets.StatusTicket"%>
<%@page import="tickets.TipoTicket"%>
<%@page import="com.sun.media.sound.AuFileReader"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="tickets.Auxiliar"%>
<%@page import="tickets.Controlador"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head >
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <title>Página del empleado</title>
    </head>
    <body>
        <div id="centro">
            <%
                Object ouser = session.getAttribute("user1");
                Object opass = session.getAttribute("password");
                String user, pass;

                if (ouser != null) {
                    user = (String) ouser;
                    pass = (String) opass;
                } else {
                    user = request.getParameter("user");
                    pass = request.getParameter("pass");
                    session.setAttribute("user1", user);
                    session.setAttribute("password", pass);
                }
                Controlador c = new Controlador();
                boolean valid = c.login(user, pass);
                if (!valid) {
                    // TODO: Enviar error a index
                    response.sendRedirect("index.jsp");
                }

                //inserta ticket
                String comentario = request.getParameter("insertaTicket");

                if (comentario != null) {
                    String tipo = request.getParameter("tipo");
                    String status = request.getParameter("status");
                    String idCliente = request.getParameter("idCliente");
                    String idUsuario = c.user.getId() + "";
                    c.conexion.ejecutaSP("Insert_ticket(" + tipo + "," + status + "," + idCliente + "," + idUsuario + ")");
                }



            %>
            <h1>¡Hola <% out.print(c.user.getNombre());%>! </h1>

            Escoge un ticket
            <form action="ticket.jsp">
                <%
                    //crear ticket
                    //consultar ticket por usuario
                    //cerrar un ticket
                    //ver tickets
                    ResultSet rs = c.conexion.ejecutaSP("TICKETS_POR_CLIENTE()");
                    String header[] = {"Ticket ID", "Fecha de creación",
                        "Nombre del cliente", "Tipo de Ticket", "Estado del Ticket"};
                    out.print(Auxiliar.creaTabla(header, rs, true));
                %>
                <br/>
                <input type="submit" name="action" value="Ver Ticket">
            </form>
            <br/>

            <h1>Crea un ticket nuevo </h1>
            Escoge el tipo de ticket
            <form action="empleado.jsp">
                <% out.print(Auxiliar.creaSelect(TipoTicket.values(), "tipo"));%>

                <br/>
                Escoge el status del ticket
                <br/>
                <% out.print(Auxiliar.creaSelect(StatusTicket.values(), "status"));%>

                <%
                    rs = c.conexion.ejecutaSP("GET_ClIENTES()");
                    String header1[] = {"ID Cliente", "Nombre"};
                    out.print(Auxiliar.creaTabla(header1, rs, false));
                %>

                Ingresa el ID del cliente <input type="text" name="idCliente">

                <input type="submit" name="insertaTicket" value="Insertar"/>
            </form>

        </div>


    </body>
</html>
